package com.edu.lxshpc.utils;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

/**
 * @author zgh
 * @date 2023/10/25
 */
@Schema(name = "Result",description = "响应结果类",requiredProperties = {"code","message","data"})
public class Result {
    /**
     * @filed.required=@javax.validation.constraints.NotEmpty
     * @filed.required=@javax.validation.constraints.NotNull
     * @filed.required=@javax.validation.constraints.NotBlank
     */
    @JsonProperty(value = "code",required = true)
    private int code;
    @JsonProperty(value = "message",required = true)
    private String message;
    @JsonProperty(value = "data",required = true)
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage("操作成功！");
        result.setData(data);
        return result;
    }

    public Result() {
    }
    public static Result success () {
        Result result = new Result();
        result.setCode(1);
        result.setMessage("操作成功！");
        return result;
    }
    public static Result fail (String message) {
        Result result = new Result();
        result.setCode(0);
        result.setMessage(message);
        return result;
    }
    public static Result fail () {
        Result result = new Result();
        result.setCode(0);
        result.setMessage("操作失败！");
        return result;
    }
}
